package com.wom.blocks;

import java.awt.Color;
import java.awt.Graphics;
import com.wom.blockfeatures.BlockRenderer;
import com.wom.blockfeatures.BlockUtils;
import com.wom.blockfeatures.LiquidBlock;
import com.wom.blockfeatures.PhysicsBlock;
import com.wom.gui.BlockTypes;
import com.wom.worldmaker.GameProperties;
import com.wom.worldmaker.GameWorld;


public class WaterBlock extends AbstractBlock{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	PhysicsBlock physics;
	public BlockRenderer renderble;
	public LiquidBlock liquid;

	public Color color=new Color(33,66,100);

	public WaterBlock(int xPos, int yPos) {
		super(xPos, yPos);

		setName("Water");



		setColor(color);
		renderble=new BlockRenderer();
		liquid=new LiquidBlock(90);

	}

	@Override
	public void renderBlock(Graphics g) {
		g.setColor(getColor());
		g.fillRect(getxPos()*GameProperties.blockSize-(int)GameWorld.player.cam.x, 
				getyPos()*GameProperties.blockSize-(int)GameWorld.player.cam.y, 
				GameProperties.blockSize, GameProperties.blockSize);

	}

	@Override
	public void updateBlock() {

		

		
		
		// remove isolated blocks
		if(BlockUtils.isIsolatedBlock(this, BlockTypes.air)){
			BlockUtils.changeInto(getxPos(),getyPos(),BlockTypes.air);
		}
		
		// remove isolated blocks from sides
		
		if(BlockUtils.isIsolatedBothSidesBlock(this, BlockTypes.air)){
			BlockUtils.changeInto(getxPos(),getyPos(),BlockTypes.air);
		}
		
		
		// if the water is cornered left or right, branch out

//		if(BlockUtils.isLeftCorneredBlock(this, BlockTypes.air)){
//			//System.out.println("open air at right");
//			BlockUtils.changeInto(getxPos()+1,getyPos(),BlockTypes.water);
//		}
//		
//		if(BlockUtils.isRightCorneredBlock(this, BlockTypes.air)){
//			//System.out.println("open air at left");
//			BlockUtils.changeInto(getxPos()-1,getyPos(),BlockTypes.water);
//		}
		
		
		
		
			liquid.fullFlow(this);
		

		
		
		//setBounds(getxPos()* GameProperties.blockSize, getyPos()*GameProperties.blockSize,GameProperties.blockSize, GameProperties.blockSize);
	}




}
